import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class Test {

    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<Integer> queue = new ArrayBlockingQueue<>(1000);
        Thread t1 = new Thread(() -> {
        int count = 0;
        while(true) {
            try {
                queue.put(count);
                System.out.println("t1生产"+count);
                //生产比消费慢
               // Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            count++;
        }
    });
        Thread t2 = new Thread(() -> {
            while(true) {
                try {
                    Integer value = queue.take();
                    System.out.println("t2消费" + value);
                    //生产比消费快
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });


        t1.start();
        t2.start();
    }
}